package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.SkinDirData;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;

public class SkinListAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private ArrayList<SkinDirData> mData;
    private String mPackageName;

    public SkinListAdapter(Context context, String packageName) {
        mInflater = LayoutInflater.from(context);
        mPackageName = packageName;
    }

    public void setData(ArrayList<SkinDirData> data) {
        mData = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {

        if (mData != null && mData.size() > 0) {
            return mData.size();
        }
        return 0;
    }

    @Override
    public SkinDirData getItem(int position) {

        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {

        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        SkinViewHolder holder;
        if (convertView == null) {
            view = mInflater.inflate(R.layout.skin_item, null);
            holder = new SkinViewHolder();
            holder.head_desc = (TextView) view.findViewById(R.id.head_descr);
            holder.iv_icon = (ImageView) view.findViewById(R.id.head_label);
            holder.isSelect = (RadioButton) view.findViewById(R.id.isSelRow);
            view.setTag(holder);
        } else {
            holder = (SkinViewHolder) view.getTag();
        }
        SkinDirData info = getItem(position);
        holder.head_desc.setText(info.skinName);
        holder.iv_icon.setImageBitmap(info.skinIcon);
        if (!StringUtil.isEmpty(mPackageName) && mPackageName.equals(info.dirName)) {
            holder.isSelect.setChecked(true);
        } else {
            holder.isSelect.setChecked(false);
        }
        return view;
    }

    class SkinViewHolder {
        public TextView head_desc;
        public ImageView iv_icon;
        public RadioButton isSelect;
    }

}
